<?php
class rekap_keuangan_bulanan extends MY_Controller{
    function rekap_keuangan_bulanan(){
        parent::MY_Controller();
        $this->data['title'] = "Rekap Keuangan Bulanan";
        $this->load->model('m_rekap_keuangan_bulanan');
        $this->load->model('m_collecting_day');
        $this->load->model('m_pemberian_beasiswa');
        $this->load->model('m_pemasukan');
        $this->load->model('m_pengeluaran');
    }
    function search(){
        $url = $this->input->post('url');
        $bulan = $this->input->post('bulan');
        $tahun = $this->input->post('tahun');
        
        redirect("$url/$bulan/$tahun");
    }
    function index($bulan = NULL,$tahun = NULL){
        $this->data['content'] = "rekap_keuangan_bulanan/v_rekap_keuangan_bulanan";
        $this->data['subLink'] = "rekap_keuangan_bulanan/search";
        $this->data['formTitle'] = "Form Rekap Keuangan Bulanan";
        $this->data['searchLink'] = "rekap_keuangan_bulanan/index";
        $this->data['listKeuanganDonaturTunggal'] = $this->m_rekap_keuangan_bulanan->getKeuanganDonaturTunggal($bulan,$tahun);    
        $this->data['listCollectingDay'] = $this->m_collecting_day->getCollectingDay($bulan,$tahun);
        $this->data['listPemberianBeasiswa'] = $this->m_pemberian_beasiswa->getPemberianBeasiswa($bulan,$tahun);
        $this->data['listPemasukan'] = $this->m_pemasukan->getPemasukan($bulan,$tahun);
        $this->data['listPengeluaran'] = $this->m_pengeluaran->getPengeluaran($bulan,$tahun);
        
        $this->render($this->data);
    }
    function rekap_keuangan_bulanan_proses(){
        $id_keuangan_donatur_tunggal = $this->input->post('id_keuangan_donatur_tunggal');
        $id_collecting_day = $this->input->post('id_collecting_day');
        $id_pemberian_beasiswa = $this->input->post('id_pemberian_beasiswa');
        $id_pemasukan = $this->input->post('id_pemasukan');
        $id_pengeluaran = $this->input->post('id_pengeluaran');
        $pemasukan = $this->input->post('pemasukan');
        $pengeluaran = $this->input->post('pengeluaran');
        $debet = 0;
        $kredit = 0;
        foreach ($pemasukan as $key => $pms){
            $debet = $debet + $pms;
        }
        foreach ($pengeluaran as $keys => $png){
            $kredit = $kredit + $png;
        }
        
        $bulan = $this->input->post('bulan');
        $tahun = $this->input->post('tahun');
        
        $data = array('id' => $bulan.$tahun,
            'pemasukan' => $debet,
            'pengeluaran' => $kredit,
            'id_keuangan_donatur_tunggal' => $id_keuangan_donatur_tunggal,
            'id_collecting_day' => $id_collecting_day,
            'id_pemberian_beasiswa' => $id_pemberian_beasiswa,
            'id_pemasukan' => $id_pemasukan,
            'id_pengeluaran' => $id_pengeluaran);
        $insert = $this->m_rekap_keuangan_bulanan->addRekapKeuanganBulanan($data);
        if($insert == TRUE){
            $this->session->set_flashdata("message",9);
        }
        
        redirect("rekap_keuangan_bulanan/index/$bulan/$tahun");
    }
}
?>
